#include"processBar.h"

//v1版本
/*
void processbar()
{
  const char* c = "|/-\\"; 
  char bar[102];
  memset(bar,'\0',sizeof(bar));

  int n = 0;
  while(n<=100)
  {
    printf("[%-100s][%d%%][%c]\r",bar,n,c[n%4]);
    fflush(stdout);
    bar[n++] = BODY;
    if(n<100) bar[n] = RIGHT;
    usleep(100000);

  }
  printf("\n");

}
*/


//v2版本
const char* c = "|/-\\"; 
char bar[102]={0};

void processbar(int rate)
{
    if(rate<0||rate>100) return;
    printf("[%-100s][%d%%][%c]\r",bar,rate,c[rate%4]);
    fflush(stdout);
    bar[rate++] = BODY;
    if(rate<100) 
      bar[rate] = RIGHT;    
}

void initbar()
{
  memset(bar,'\0',sizeof(bar));
}

